<?php
function getDaysInWeek ($weekNumber, $year, $dayStart = 1) {
    // Count from '0104' because January 4th is always in week 1
    // (according to ISO 8601).
    $time = strtotime($year . '0104 +' . ($weekNumber - 1).' weeks');
    // Get the time of the first day of the week
    $dayTime = strtotime('-' . (date('w', $time) - $dayStart) . ' days', $time);
    // Get the times of days 0 -> 6
    $dayTimes = array ();
    for ($i = 0; $i < 7; ++$i) {
        $dayTimes[] = strtotime('+' . $i . ' days', $dayTime);
    }
    // Return timestamps for mon-sun.
    return $dayTimes;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <link href="../public/css/calendar.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="../public/js/calendar.js"></script>

        <style type="text/css">
            body { font-size: 11px; font-family: "verdana"; }

            pre { font-family: "verdana"; font-size: 10px; background-color: #FFFFCC; padding: 5px 5px 5px 5px; }
            pre .comment { color: #008000; }
            pre .builtin { color:#FF0000;  }
        </style>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
        <table width="100%" border="0" cellspacing="0" cellpadding="5">
            <tr>
                <td>                 
                    <table width="100%" border="0" cellspacing="0" cellpadding="5">
                        <tr>
                            <td>
                                <!--    <form name="form2" method="post" action="" id="form2">-->
                                <div style="float: left;">
                                    <div style="float: left; padding-right: 3px; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<?=$this->lang->line('cal_from');?>:</div>
                                    <div style="float: left;">
                                        <?php
                                        $thisweek = date('W');
                                        $thisyear = date('Y');

                                        $dayTimes = getDaysInWeek($thisweek, $thisyear);
                                        //----------------------------------------

                                        $date1 = date('Y-m-d', $dayTimes[0]);
                                        $date2 = date('Y-m-d', $dayTimes[(sizeof($dayTimes)-1)]);

                                        //from
                                        $this->date3->tc_calendar("date3", true, false);
                                        $this->date3->setIcon("public/images/calendar/iconCalendar.gif");
                                        $this->date3->setDate(date('d'), date('m'), date('Y'));
                                        $this->date3->setPath("./");
                                        $this->date3->setYearInterval(date('Y'), date('Y')+ 2);
                                        $this->date3->dateAllow(date('Y').'-'.date('m').'-'.date('d'), "", false);
                                        $this->date3->startMonday(true);
                                        $this->date3->writeScript();
                                        ?>
                                    </div>
                                </div>
                                <div style="float: left;">
                                    <div style="float: left; padding-left: 3px; padding-right: 3px; line-height: 18px;">&nbsp;&nbsp;&nbsp;<?=$this->lang->line('cal_to');?>:</div>
                                    <div style="float: left;">
                                        <?php
                                        $this->date4->tc_calendar("date4", true, false);
                                        $this->date4->setIcon("public/images/calendar/iconCalendar.gif");
                                        $this->date4->setDate(date('d', strtotime($date2)), date('m', strtotime($date2)), date('Y', strtotime($date2)));
                                        $this->date4->setPath("./");
                                        $this->date4->setYearInterval(date('Y'), date('Y')+ 2);
                                        $this->date4->startMonday(true);
                                        $this->date4->dateAllow(date('Y').'-'.date('m').'-'.date('d')+1,"",  false);

                                        $this->date4->writeScript();
                                        ?>
                                    </div>
                                </div>

                      <!--           <input type="button" name="button2" id="button2" value="Check the value" onClick="javascript:alert('Date select from '+this.form.date3.value+' to '+this.form.date4.value);">
                                </form>-->
                            </td>
                        </tr>
                    </table>
            </tr>
        </table>
    </body>
</html>
